
export function getCookie(name: string) {
    var strcookie = document.cookie;//获取cookie字符串
    var arrcookie = strcookie.split("; ");//分割
    //遍历匹配
    for ( var i = 0; i < arrcookie.length; i++) {
        var arr = arrcookie[i].split("=");
        if (arr[0] == name){
            return arr[1];
        }
    }
    return "";
}

export const stopPropagation = (e: React.MouseEvent | React.ChangeEvent) => { 
    e.stopPropagation();
    e.nativeEvent.stopPropagation();
}

// 函数节流
type ThrottleFunc<T extends any[]> = (...args: T) => void;

export function throttle<T extends any[]>(func: ThrottleFunc<T>, delay: number = 100): ThrottleFunc<T> {
  let timeoutId: ReturnType<typeof setTimeout> | undefined;
  let lastExecTime = 0;
  return  (...args: T) => {
    const currentTime = Date.now();

    if (currentTime - lastExecTime > delay) {
      lastExecTime = currentTime;
      func.apply(null, args);
    } else {
      if (timeoutId) {
        clearTimeout(timeoutId);
      }

      timeoutId = setTimeout(() => {
        lastExecTime = currentTime;
        func.apply(null, args);
      }, delay);
    }
  };
}

// 获取url参数的方法 ts格式
export function getQueryString(name: string = '') {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  // var r = window.location.search.substr(1).match(reg);
  const search = window.location.href.split('?')[1]
  if (!search) return '';
  var r = search.match(reg);
  if (r != null) return decodeURIComponent(r[2]); return null;
}
export * from './point'
